<template>
  <!-- 作业管理  -->
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="作业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入作业名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
      </el-form-item>
    </el-form>
    <el-row class=" mt2">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5" style="margin:0 10px;">
        <el-upload
          ref="upload"
          class="upload-demo"
          action="#"
          accept=".xlsx, .xls"
          :auto-upload="false"
          :show-file-list="false"
        >
          <el-button class="el-button el-button--mini is-"><i
            class="el-icon-upload"
          ></i><span>导入</span></el-button>
        </el-upload>
      </el-col>
      <el-col :span="1.5">
        <el-button class="el-button el-button--mini is-" @click="downloadExcelDC">
          <!----><i class="el-icon-download"></i><span>导出</span></el-button>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-table :data="noticeList" :header-cell-style="{ background: '#F3F5FC' }">
          <el-table-column label="序号" align="center" width="100">
            <template slot-scope="scop">
              {{ scop.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column
            label="作业名称"
            prop="taskName"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="启用状态"  prop="configStatus">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.configStatus"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="handleUpdate(scope.row)"
              >编辑
              </el-button>
              <el-button
                size="mini"
                type="text" 
                @click="handleDeploy(scope.row)"
              >一键配置
              </el-button>
              <el-button
                size="mini"
                type="text"  
                @click="handleLook(scope.row)"
              >查看日志
              </el-button>
              <el-button
                size="mini"
                type="text"
                @click="handleDelete(scope.row)"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 添加或修改对话框 -->
    <editDialog ref="editRef" :title="title" :formData="formData"/>
    <deployDialog ref="deployRef" :title="deployTitle"></deployDialog>
    <viewLog ref="viewLogRef" title="查看日志"></viewLog>
  </div>
</template>

<script>
import taskListData from './mockData/taskListData.json'
import editDialog from '@/components/accessProduct/jobScheduling/emitDialog.vue'
import deployDialog from '@/components/accessProduct/jobScheduling/deployDialog.vue'
import viewLog from '@/components/accessProduct/jobScheduling/viewLog.vue'

export default {
  name: 'taskList',
  components: { editDialog, deployDialog, viewLog },
  data() {
    return {
      deployTitle: '',
      title: '',
      noticeList: [],
      queryParams: {
        name: '',
        pageNum: 0,
        pageSize: 20
      },
      formData: {},
      total: 0
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    /**导出**/
    downloadExcelDC() {
      let a = document.createElement('a')
      a.href = '/static/export.xlsx'
      a.download = '导出数据.xlsx'
      a.style.display = 'none'
      document.body.appendChild(a)
      a.click()
      a.remove()
    },
    getList() {
      this.total = taskListData.page.totalCount
      this.noticeList = taskListData.page.list
    },
    // 新增
    handleAdd() {
      this.$refs.editRef.isOpen = true
      this.$refs.editRef.active = 0
      this.title = '添加'

    },
    // 查询
    handleQuery() {

    },
    // 编辑
    handleUpdate() {
      this.$refs.editRef.isOpen = true
      this.$refs.editRef.active = 0
      this.title = '编辑'
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const name = row.taskName
      this.$modal.confirm('是否确认删除"' + name + '"的数据项？').then(function() {
        return true
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 一键配置 **/
    handleDeploy(row) {
      this.$refs.deployRef.isOpen = true
      this.deployTitle = '配置'
    },
    handleLook() {
      this.$refs.viewLogRef.isOpen = true

    }
  }
}
</script>

<style lang="scss" scoped>
.box {
  padding: 2px 5px;
  margin-right: 5px;
  background: #f2f2f2;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
}
</style>
